/**
 * Copyright 2008 Adam Ruggles.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 * http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package kiff.action;

import java.io.Serializable;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.opensymphony.xwork2.Action;

/**
 * Logout Action, used to allow the user to log out.
 * @author Adam
 * @version $Id$
 * 
 * Created on Nov 8, 2008 at 12:28:43 PM 
 */
public class LogoutAction implements ServletRequestAware, Serializable {
	/**
	 * Serial Version UID.
	 */
	private static final long serialVersionUID = -5615396306298191276L;

	/**
	 * Http Servlet Request, used to invalidate the session.
	 */
	private HttpServletRequest request;

	/**
     * The <code>Logger</code> is used by the application to generate a log messages.
     */
    private final Logger logger = LoggerFactory.getLogger(LogoutAction.class);

	/**
	 * {@inheritDoc}
	 * @see org.apache.struts2.interceptor.ServletRequestAware#setServletRequest(javax.servlet.http.HttpServletRequest)
	 */
	public void setServletRequest(final HttpServletRequest request) {
		this.request = request;
	}

	/**
	 * Invalidates the session so the user is logged out.
	 * @return Action.LOGIN.
	 * @throws Exception If an error occurs invalidating the session.
	 */
	public String execute() throws Exception {
		logger.debug("executing logout.");
		try {
			request.getSession().invalidate();
		} catch (IllegalStateException e) {
			logger.warn("LogoutAction.execute() caught an IllegalStateException", e);
		}
		return Action.SUCCESS;
	}
}
